package com.cloud.bc.controller.pc;

import cn.hutool.core.convert.Convert;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cloud.bc.controller.BaseController;
import com.cloud.bc.model.domain.UserInfo;
import com.cloud.bc.model.entity.BcLikes;
import com.cloud.bc.model.entity.BcSingles;
import com.cloud.bc.model.request.LikeRequest;
import com.cloud.bc.service.BcFootprintsService;
import com.cloud.bc.service.BcLikesService;
import com.cloud.bc.service.BcSinglesService;
import com.cloud.bc.service.BcUsersService;
import com.cloud.bc.util.JiaoYouPageHelper;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

//PC心动
@Controller
@AllArgsConstructor
@RequestMapping("center/like")
public class PcCenterLikeController extends BaseController {
    private final BcUsersService bcUsersService;
    private final BcLikesService bcLikesService;
    private final BcSinglesService bcSinglesService;

    /**
     * 心动
     */
    @GetMapping("")
    public ModelAndView index(HttpServletRequest request, HttpServletResponse response,
                              LikeRequest req) {
        ModelAndView view = baseView(request, "心动-用户中心", "pc/center/like/index");
        view.addObject("bodyCss", " page_manage page_manage_like");
        UserInfo userInfo = bcUsersService.getUserInfo(request);
        Page p = new Page();
        p.setCurrent(Convert.toInt(req.getPage(), 0) <= 0 ? 1 : req.getPage());
        p.setSize(10);
        //默认是我心动的
        Integer type = req.getType();
        type = Convert.toInt(type, 0) <= 0 ? 1 : type;
//        BcLikes bcLikes = new BcLikes();
        List<BcSingles> list = null;
        if (type.equals(1)) {
            //我心动的
            list = bcLikesService.selectMyLike(p, userInfo.getId());
        } else if (type.equals(2)) {
            //心动我的
            list = bcLikesService.selectLikeMe(p, userInfo.getId());
        } else if (type.equals(3)) {
            //互相心动的
            list = bcLikesService.selectMutual(p, userInfo.getId());
        }
        if (null != list) {
            list.forEach(item -> {
                item.setAge(bcSinglesService.ageConvert(item.getBirthday()));
            });
        }
        JiaoYouPageHelper jiaoYouPageHelper = new JiaoYouPageHelper();
        view.addObject("page", jiaoYouPageHelper.getBcPageHTML(p, request));
        view.addObject("likeList", list);
//        view.addObject("isVip", bcSinglesService.isVip(userInfo));
        view.addObject("type", type);
        return view;
    }

}
